package com.example.exception_demo.controller;

import com.example.exception_demo.entity.User;
import com.example.exception_demo.exception.InvalidDattaException;
import com.example.exception_demo.service.UserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {
    private UserService service;
    public UserController(UserService service){
        this.service=service;
    }

    @GetMapping("/{id}")
    public User getById(@PathVariable int id){
        User entity=service.getById(id);
        if (entity.equals(null)){
            throw new InvalidDattaException("Username or email cannot be null");
        }
        return entity;
    }

}
